/**
     * @descripting 轮询功能
     * @param {Function} fn     网络请求方法
     * @param {Object} data     网络请求参数
     * @param {Number} delay    轮询间隔时间
     */

let timer = null

export function polling(fn, data, delay = 5000) {
    return new Promise((resolve, reject) => {
        fn(data).then(res => {
            resolve(res)
        }).catch(error => {
            timer = setTimeout(() => {
                resolve(polling(fn, data, delay = 5000));
            }, delay)
        })
    })
}


export function clearPolling(){
    clearTimeout(timer)
}